<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
    <head>
        <th:block th:include="include :: header('课程列列表')"/>
    </head>
    <body class="gray-bg">
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <div class="select-list">
                            <ul>
                                <li class="col-sm-3">
                                    <label>所属课程：</label>
                                    <div>
                                        <div class="input-group">
                                            <input id="treeId" name="courseId" type="hidden" th:value="${course?.id}"/>
                                            <input class="form-control" type="text" onclick="selectManageTree()"
                                                   id="treeName"
                                                   readonly="true" th:value="${course?.courseName}">
                                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                                        </div>
                                    </div>
                                </li>
                                <li>
                                    <label>讲师：</label>
                                    <select name="teacher"
                                            th:with="type=${@bizCourseExpertServiceImpl.selectBizCourseExpertList()}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.name}"
                                                th:value="${dict.id}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>状态：</label>
                                    <select name="visible" th:with="type=${@dict.getType('biz_visible_status')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                                th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                            class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                            class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="add()" shiro:hasPermission="biz:coursedetail:add">
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="biz:coursedetail:edit">-->
                    <!--                    <i class="fa fa-edit"></i> 修改-->
                    <!--                </a>-->
                    <!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="biz:coursedetail:remove">-->
                    <!--                    <i class="fa fa-remove"></i> 删除-->
                    <!--                </a>-->
                    <a class="btn btn-warning" onclick="$.table.exportExcel()"
                       shiro:hasPermission="biz:coursedetail:export">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>


            </div>
        </div>
        <th:block th:include="include :: footer"/>
        <script th:inline="javascript">
            var editFlag     = [[${@permission.hasPermi('biz:coursedetail:edit')}]];
            var removeFlag   = [[${@permission.hasPermi('biz:coursedetail:remove')}]];
            var visibleDatas = [[${@dict.getType('biz_visible_status')}]];
            var prefix       = ctx + "biz/coursedetail";

            $(function () {
                var options = {
                    url: prefix + "/list",
                    createUrl: prefix + "/add/{id}",
                    updateUrl: prefix + "/edit/{id}",
                    removeUrl: prefix + "/remove",
                    exportUrl: prefix + "/export",
                    modalName: "课程列",
                    columns: [{
                        title: '操作',
                        width:'220px',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var actions = [];
                            actions.push(
                                '<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="addExam(\'' + row.id + '\')"><i class="fa fa-edit"></i>添加试题</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push(
                                '<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                        }
                    },
                        {
                            field: 'id',
                            title: 'id',
                            visible: false
                        },
                        {
                            field: 'courseName',
                            title: '所属课程'
                        },
                        {
                            field: 'courseId',
                            title: '所属课程ID',
                            visible: false
                        },
                        {
                            field: 'title',
                            title: '标题'
                        },
                        // {
                        //     field: 'coverUrl',
                        //     title: '封面图片'
                        // },
                        {
                            field: 'introduce',
                            title: '课程介绍'
                        },
                        {
                            field: 'teacherName',
                            title: '讲师'
                        }, {
                            field: 'teacher',
                            title: '讲师',
                            visible: false
                        },
                        {
                            field: 'pptUrl',
                            title: '课件资料',
                            formatter: function (value, row, index) {
                                if (!row.pptUrl) {
                                    return ''
                                }
                                var actions = [];
                                actions.push(
                                    '<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="readPPT(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                                return actions.join('');
                            }
                        },
                        {
                            field: 'videoUrl',
                            title: '视频资料',
                            formatter: function (value, row, index) {
                                if (!row.videoUrl) {
                                    return ''
                                }
                                var actions = [];
                                actions.push(
                                    '<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="play(\'' + row.id + '\')"><i class="fa fa-edit"></i>播放</a> ');
                                return actions.join('');
                            }
                        },
                        {
                            field: 'orderNum',
                            title: '显示顺序'
                        },
                        {
                            field: 'visible',
                            title: '状态',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(visibleDatas, value);
                            }
                        }
                    ]
                };
                $.table.init(options);
            });

            function selectManageTree() {
                var options = {
                    title: '课程选择',
                    width: "380",
                    url: prefix + "/selectManageTree/" + $("#treeId").val(),
                    callBack: doSubmit
                };
                $.modal.openOptions(options);
            }

            function doSubmit(index, layero) {
                var tree = layero.find("iframe")[0].contentWindow.$._tree;
                if (checkL3(tree)) {
                    var body = layer.getChildFrame('body', index);
                    $("#treeId").val(+body.find('#treeId').val()+10000);
                    $("#treeName").val(body.find('#treeName').val());
                    console.log('courseid = ' + $("#treeId").val())
                    layer.close(index);
                }
            }

            function checkL3(_tree) {
                var nodes = _tree.getSelectedNodes();
                if (nodes.length == 0) {
                    $.modal.msgError("请选择节点后提交");
                    return false;
                }
                for (var i = 0; i < nodes.length; i++) {
                    if (nodes[i].level != 2) {
                        $.modal.msgError("数据不正确，请选择第三级菜单");
                        return false;
                    }

                }
                return true;
            }

            function add() {
                $.operate.add($("#treeId").val())
            }

            function play(id) {
                // var options = {
                //     title: '视频播放',
                //     width: "800",
                //     url: prefix + "/video/" + id,
                //     callBack: function (index){
                //         console.log('----callBack---')
                //         layer.close(index);
                //     }
                // };
                // $.modal.openOptions(options);
                $.modal.openTab('视频播放', prefix + "/video/" + id);
            }

            function readPPT(id) {
                // var options = {
                //     title: '视频播放',
                //     width: "800",
                //     url: prefix + "/video/" + id,
                //     callBack: function (index){
                //         console.log('----callBack---')
                //         layer.close(index);
                //     }
                // };
                // $.modal.openOptions(options);
                $.modal.openTab('查看文档', prefix + "/ppt/" + id);
            }

            function addExam(id){
                console.log('>>>>添加考试试题：'+id)

                $.modal.openTab('添加试题', prefix + "/addExam/" + id);
            }
        </script>
    </body>
</html>